package edu.hunan.cxb18.controller;

import edu.hunan.cxb18.pojo.Product;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author AuthorName
 * @create 2020-04-03 14:58
 */
@Controller
public class ThymeleafController {
    @RequestMapping("/thymeleaf")
    public String test(Model model, Map<String,Object> map){
        map.put("datas","thymeleaf");
        model.addAttribute("name","haoren");
      return "hello";
    }
    @RequestMapping("/fragments")
    public String fragmentTest(){

      return "fragment";
    }
    @RequestMapping("/common")
    public String fragmentTest01(){

        return "commons";
    }
    @RequestMapping("/list")
    public String findProductList(Map<String,Object> map){
        List<Product> products = new ArrayList<>();
//        products.add(new Product(1002,"格瓦斯",3.50, LocalDate.now(),true));
//        products.add(new Product(1003,"盐汽水",5.50, LocalDate.now(),false));
//        products.add(new Product(1004,"盐汽水",5.50, LocalDate.now(),false));
        map.put("products",products);
        return "list";
    }
}
